package com.xyh.controller;

import com.xyh.pojo.entity.Student;
import com.xyh.pojo.vo.StudentVo;
import com.xyh.service.StudentService;
import com.xyh.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * TODO
 *
 * @author 丁德成
 * @explain
 * @date 2023/4/12
 */
@RestController
@RequestMapping("student")
@Api(tags = "学生操作API")
public class StudentController {

    @Autowired
    private StudentService stuService;

    @PostMapping("list/{current}/{pageSize}")
    @ApiOperation(value = "依据条件查询学生")
    public Result list(
            @ApiParam(value = "当前页面", name = "current", required = true, defaultValue = "1")
            @PathVariable Integer current,
            @ApiParam(value = "每页条数", name = "pageSize", required = true, defaultValue = "5")
            @PathVariable Integer pageSize,
            @RequestBody StudentVo stuVo
    ) {
        return stuService.findByPage(current, pageSize, stuVo);
    }

    @PostMapping("fId/{smpno}")
    @ApiOperation(value = "根据id查询学生")
    public Result fId(
            @ApiParam(value = "学生id", name = "smpno", required = true)
            @PathVariable Integer smpno
    ){
        return stuService.findById(smpno);
    }

    @PostMapping("addUser")
    @ApiOperation(value = "插入学生信息")
    public Result insert(@RequestBody Student student){
        return stuService.insertOneSOS(student);
    }

    @DeleteMapping("deleteByIdSOS/{smpno}")
    @ApiOperation(value = "删除学生信息")
    public Result delete(
            @ApiParam(value = "学生id", name = "smpno", required = true)
            @PathVariable Integer smpno
    ){
        return stuService.deleteByIdSOS(smpno);
    }

    @PutMapping("updateS")
    @ApiOperation(value = "修改学生信息")
    public Result update(@RequestBody Student student){
        return stuService.updateSOS(student);
    }
}
